import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_test_demo/pages/home/components/ProjectInfo.dart';
import 'package:flutter_test_demo/static/colors/MyColors.dart';

class OrderedPage extends StatelessWidget {
  const OrderedPage({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
      // 已订购
    List onOrder = [
      {"image":"images/book/1.jpg","name":"孩子认真学习", "money": '12.3',"des":"这是一个 '孩子认真学习' 的故事"},
      {"image":"images/book/2.jpg","name":"情商决定一生", "money": '12.3',"des":"这是一个 '情商决定一生' 的故事"},
      {"image":"images/book/3.jpg","name":"道德经", "money": '12.3',"des":"这是一个 '道德经' 的故事"},
      {"image":"images/book/4.jpg","name":"深爱这个城", "money": '12.3',"des":"这是一个 '深爱这个城' 的故事"},
      {"image":"images/book/5.jpg","name":"只因目中无人", "money": '12.3',"des":"这是一个 '只因目中无人' 的故事"},
      {"image":"images/book/6.jpg","name":"人文讲坛目录", "money": '12.3',"des":"这是一个 '人文讲坛目录' 的故事"},
      {"image":"images/book/7.jpg","name":"犯罪心理", "money": '12.3',"des":"这是一个 '犯罪心理' 的故事"},
      {"image":"images/book/8.jpg","name":"养猪学", "money": '12.3',"des":"这是一个 '养猪学' 的故事"},
    ];

    return Column(
      children: <Widget>[
        // 已订购图书
          Padding(
            padding: EdgeInsets.symmetric(
              vertical: 20.0,
              horizontal: 12.0
            ),
            child: Row(
              children: <Widget>[
                DecoratedBox(
                  decoration: BoxDecoration(
                    color: MyColor.titleColor,
                  ),
                  child: ConstrainedBox(
                    constraints: BoxConstraints.tightFor(
                      width: 4.0,
                      height: 20.0
                    ),
                  ),
                ),
                Padding(
                  padding: EdgeInsets.only(left: 15.0),
                  child: Text(
                    "已订购图书",
                    style: TextStyle(
                      color: MyColor.titleColor,
                      fontSize: 18.0
                    ),
                  ),
                ),
              ],
            ),
          ),
          // 已订购图书 grid
          Wrap(
            spacing: 10.0,
            runSpacing: 20.0,
            children:  onOrder.map((item) =>
            ConstrainedBox(
              constraints: BoxConstraints.tightFor(
                height: 150.0,
                width: 90.0
              ),
              child: GestureDetector(
                  onTap: (){
                    JumpProjectInfo(context,item);
                  },
                  child: Column(
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: <Widget>[
                        ConstrainedBox(
                          constraints: BoxConstraints.tightFor(
                            height: 100.0,
                    
                          ),
                          child: Image.asset(
                            item['image'],
                            width: 80.0,
                            height: 50.0,
                            fit: BoxFit.contain,
                          ),
                        ),
                        
                        Text(
                          item['name'],
                          overflow: TextOverflow.ellipsis,
                          style: TextStyle(
                            height: 1.2,
                          ),
                        ),
                        Row(
                          mainAxisAlignment: MainAxisAlignment.spaceAround,
                          children: <Widget>[
                            Text("金额："),
                            Text(
                              "\$"+ (item['money'] ?? 0).toString(),
                              style: TextStyle(
                                color: Colors.red
                              ),
                            )
                          ],
                        )
                      ],
                    ),
                  ),
                )
              ).toList()
            ),
          
      ],
    );
  }
}

void JumpProjectInfo(BuildContext context, data){
  Navigator.push(context,   MaterialPageRoute(builder: (context) => ProjectInfo(reInfo: data),));
}